package com.xlx.ui.controller;

import com.alibaba.fastjson.JSONObject;
import com.xlx.ui.domain.DTO.MessagQuery;
import com.xlx.ui.domain.DTO.MessageDTO;
import com.xlx.ui.domain.MO.Friends;
import com.xlx.ui.domain.MO.Message;
import com.xlx.ui.domain.VO.ResultBody;
import com.xlx.ui.service.MessageService;
import com.xlx.ui.service.error.errorImpl.BizException;
import com.xlx.ui.service.error.errorImpl.ResponseCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @author: 张川
 * @date: 2021-04-18 11:08
 */
@RestController
@RequestMapping("/message")
@Api(tags = "消息管理")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @ApiOperation(value = "查询消息记录")
    @GetMapping("")
    public ResultBody message(MessagQuery query){
        List<Message> messages = messageService.query(query);
        return ResultBody.success(messages);
    }

    @ApiOperation(value = "清空消息")
    @DeleteMapping("/{userId}/{receive}")
    public ResultBody remove(@PathVariable(value = "userId") Integer userId,@PathVariable(value = "receive") Integer receive){
        if(userId ==null||receive==null){
            throw new BizException(ResponseCodeEnum.PARAMETER_INVALID);
        }
       Boolean delete = messageService.remove(userId,receive);
        return delete?ResultBody.success():ResultBody.error();
    }
}
